<template>
  <div class="home-page layout">
    <!-- 左侧菜单 -->
    <LeftMenu></LeftMenu>
    <!-- 内容区域 -->
    <div class="page-content">
      <!-- 头部显示 -->
      <div class="page-header">
        <div class="adress-text">{{ home.userInfoVo.companyName }}</div>
        <div class="flex timer">
          <p>本次登录时间：{{ getObjectKey('loginTime') | dateFormat('M') }}</p>
          <p>本次登录IP：{{ getObjectKey('ipAddress') }}</p>
        </div>
      </div>
      <div :class="routeType == 3 ? 'body-box-need-footer' : 'body-box'">
        <keep-alive>
          <router-view
            v-if="$route.meta.keepAlive"
            :key="isRouterShow"
          ></router-view>
        </keep-alive>
        <router-view
          v-if="!$route.meta.keepAlive"
          :key="isRouterShow"
        ></router-view>
      </div>
      <div class="page-footer" v-if="routeType == 3">
        <div class="footer-text">中国信息通信研究院提供数据支持</div>
      </div>
    </div>
  </div>
</template>
<script>
import { mapState, mapMutations } from 'vuex'

import LeftMenu from '@/components/leftMenu/leftMenu.vue'
export default {
  provide() {
    return {
      reload: this.reload
    }
  },
  components: {
    LeftMenu
  },
  data() {
    return {
      routeType: '',
      isRouterShow: true,
      ifKeepAlive: true
    }
  },
  created() {
    this.routeType = this.$route.meta ? this.$route.meta.routeType : null
  },
  mounted() {},
  computed: {
    ...mapState(['home'])
  },
  watch: {
    $route: {
      handler(val, _oldval) {
        this.routeType = val.meta.routeType
        if (_oldval.path == '/gisPage/thematic-research') {
          this.$router.go(0)
          // this.clearData()
          // this.isRouterShow = !this.isRouterShow
          // this.$nextTick(() => {
          //   // setTimeout(() => {
          //   this.isRouterShow = !this.isRouterShow
          //   // }, 1000)
          // })
          // this.$forceUpdate()
        }
      },
      deep: true
    }
  },
  methods: {
    ...mapMutations('gisForm', ['clearData']),
    getObjectKey(key) {
      const obj = this.home.userInfoVo.thisTime
        ? JSON.parse(this.home.userInfoVo.thisTime)[key]
        : null
      return obj
    },
    async reload() {
      this.isRouterShow = false
      await this.$nextTick()
      this.isRouterShow = true
    }
  }
}
</script>
<style lang="scss" scoped>
.home-page {
  display: flex;
  height: 100%;
  width: 100%;
  background: #f4f6f9;

  .page-content {
    flex-grow: 1;
    width: calc(100% - 70px);
  }
  .page-header {
    display: flex;
    justify-content: space-between;
    height: 50px;
    line-height: 50px;
    background: #fff;
    padding: 0 20px;
    margin-bottom: 6px;
    box-shadow: 0px 0px 16px 0px rgba(6, 14, 33, 0.04);
    .adress-text {
      font-size: 26px;
      color: #060e21;
    }
    .timer {
      font-size: 12px;
      color: #666;
      p {
        margin-left: 15px;
      }
    }
    .homeBtn {
      margin-left: 25px;
      cursor: pointer;
      i {
        margin-right: 7px;
      }
    }
  }
  .flex {
    display: flex;
  }
  .page-footer {
    height: 30px;
    line-height: 30px;
    display: flex;
    justify-content: space-between;
    padding: 0 10px;
    background: #f4f6f9;
    .footer-text {
      color: #0e2345;
      font-size: 12px;
    }
  }
}
</style>
